package com.project2.controller;

import com.project2.bean.PageBo;
import com.project2.bean.ResultVo;
import com.project2.bean.bo.WxCollectAddOrDeleteBo;
import com.project2.bean.vo.WxShowCollectListVo;
import com.project2.service.WxCollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author: MH
 * @Date: 2022-08-15 09:55
 * @Description: 前台商品和专题收藏
 */
@RestController
@RequestMapping("wx/collect")
public class WxCollectController {
    @Autowired
    WxCollectService wxCollectService;

    /**
    *@Author: MH
    *@date: 2022/8/15 20:23
    *@Description:收藏和取消收藏,不过如果用户还没登录需要先登录
    */
    @RequestMapping("addordelete")
    public ResultVo addOrDeleteCollect(@RequestBody WxCollectAddOrDeleteBo addOrDeleteBo, HttpServletRequest httpServletRequest) {
        Integer integer = wxCollectService.addOrDeleteCollect(addOrDeleteBo, httpServletRequest);
        if(integer==null){
            return ResultVo.ok("请登录",501);
        }
        return ResultVo.ok();
    }

    /**
    *@Author: MH
    *@date: 2022/8/15 20:23
    *@Description:展示用户的收藏列表
    */
    @RequestMapping("list")
    public ResultVo showCollect(Byte type, PageBo pageBo) {
        WxShowCollectListVo collectVo = wxCollectService.showCollect(type, pageBo);
        return ResultVo.ok(collectVo);
    }
}
